<template>
  <div class="con">
    <div class="contbox6_10">
      <p class="titlelist6_10">
        业务管理
        <span style="color: #999">&nbsp;&nbsp;/&nbsp;&nbsp;</span>业务列表
      </p>
      <div class="content">
        <div class="sousuojg6_10">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="业务类型" style="float: left;">
              <el-select clearable v-model="form.busUid" placeholder="请选择业务类型">
                <el-option
                  v-for="items in bussinessType"
                  :key="items.uid"
                  :label="items.busName"
                  :value="items.uid"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="操作时间">
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="开始日期"
                v-model="form.startDate"
                style="width: 100%"
              ></el-date-picker>
              <div class="times">-</div>
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="结束日期"
                v-model="form.endDate"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="状态" style="float: left;">
              <el-select v-model="form.status" placeholder="请选择状态">
                <el-option label="全部" value></el-option>
                <el-option label="启用" value="0"></el-option>
                <el-option label="停用" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="buttons">
          <el-button
            type="primary"
            @click="handleSelectLists"
          >搜索</el-button>
          <el-button @click="resetTheSearch">重置</el-button>
        </div>
        <el-table
          :data="list"
          tooltip-effect="dark"
          :header-cell-style="{ background: '#F9FAFC', color: '#222' }"
          stripe
          border
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '0px' }"
          ref="multipleTable">
          <!-- <el-table-column width="60px" type="index" label="序号" ></el-table-column> -->
          <el-table-column min-width="200" label="业务类型" prop="busName"></el-table-column>
          <el-table-column min-width="160" label="操作时间" prop="createDate"></el-table-column>
          <el-table-column label="状态" min-width="100">
            <template slot-scope="scope">
              <div  @click="bigClick(scope.row)">
            <el-switch
              v-model="scope.row.status"
              active-color="#56BB8A"
              inactive-value="1"
              @change="statusChange"
              active-value="0"
              inactive-color="#C0C4CC">
            </el-switch></div>
          </template>
          </el-table-column>
        </el-table>
        <div style="font-size: 16px; margin-top: 30px">
          <el-pagination
            style="text-align: right"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="form.page"
            :page-sizes="[20, 50, 100]"
            :page-size="form.number"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
      </div>
    </div>
  
</template>

<script>
import https from "../../plugins/https.js"
import { CompareDate } from "../../assets/js/commion";
export default {
  data() {
    return {
      val:"",
      total:0,
      form: {
        status:"",
        startDate:"",
        endDate:"",
        busUid:"",
        page:1,
        number:20
      },
      list:[],
      bussinessType:[]
    };
  },
  created(){
    this.lists()
    https.getAllBusInfo({staus:""}).then(res=>{
      console.log(res)
      this.bussinessType=res.data.data
    }).catch(err=>{})
  },
  methods:{
    // 业务列表
    lists(){
      https.bussinessList(this.form).then(res=>{
        if(res.data.code=="0000"){
          this.list=res.data.data
          this.total=res.data.total
        }else{
          layer.open({
            content: res.data.msg,
            skin: "msg",
            time:  2 //2秒后自动关闭
          });
        }
      }).catch(err=>{})
    },
    //搜索
    handleSelectLists(){
      this.form.page=1
       let bool = CompareDate(this.form.startDate, this.form.endDate);
      if (this.form.startDate != "" && this.form.endDate != "") {
        if (bool) this.lists();
        else this.warrys();
      } else {
        this.lists();
      }
    },
     // 校验时间的一个方法
    warrys() {
      layer.open({
        content: "结束时间不能早于开始时间",
        skin: "msg",
        time: 2 //1秒后自动关闭
      });
    },
    // 重置
    resetTheSearch(){
      this.form={
        status:"",
        startDate:"",
        endDate:"",
        busUid:"",
        page:1,
        number:20
      }
      this.lists()
    },
    //每页几条数据
    handleSizeChange(val) {
      this.SelectData=[]
      this.form.number = val; //动态改变
      this.form.page = 1;
      this.lists();
    },
    //当前页
    handleCurrentChange(val) {
      this.SelectData=[]
      this.form.page = val; //动态改变
      this.lists();
    },
    // 状态改变
    statusChange(val){
      console.log(val)
      this.val=val
      // this.bigClick()
    },
    bigClick(val){
      https.changeBusStatus({busUid:val.uid}).then(res=>{
        if(res.data.code=="0000"){
          this.lists()
        }else{
           layer.open({
            content: res.data.msg,
            skin: "msg",
            time:  2 //2秒后自动关闭
          });
        }
      }).catch(err=>{})
    }
  }
};
</script>

<style scoped>
.con {
  position: relative;
}
/* 单独样式 */
.contbox6_10 {
  width: 100%;
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.sousuojg6_10 {
  width: 100%;
}
.times {
  width: 20px;
  display: inline-block;
  text-align: center;
}
.buttons > .el-button {
  width: 100px;
  padding: 7px;
  height: 32px;
}
</style>